package com.yun.springcloud.controller;

import com.yun.springcloud.entities.CommonResult;
import com.yun.springcloud.entities.Payment;
import com.yun.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult addPayment(@RequestBody Payment payment) {
        int result = paymentService.addPayment(payment);
        log.info("测试");
        if (result == 1) {
            //成功
            return new CommonResult(200, "添加成功", payment);
        } else {
            return new CommonResult(500, "系统繁忙添加失败", null);
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult addPayment(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPymentById(id);
        log.info("测试");
        if (payment != null) {
            //成功
            return new CommonResult(200, "查询成功", payment);
        } else {
            return new CommonResult(500, "系统繁忙查询失败", null);
        }
    }

}
